<template>
  <Wrapper>
    <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
    <el-table :data="tableData" border highlight-current-row style="margin-top: 22px">
      <el-table-column v-for="item of tableHeader" :key="item" :prop="item" :label="item" />
    </el-table>
  </Wrapper>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import UploadExcel from '@/components/upload-excel'

const tableData = ref([])
const tableHeader = ref([])

function beforeUpload(file) {
  const isLt1M = file.size / 1024 / 1024 < 1

  if (isLt1M) {
    return true
  }

  ElMessage.warning('不能上传超过1MB的文件')
  return false
}
function handleSuccess({ results, header }) {
  tableData.value = results
  tableHeader.value = header
}
</script>
